package com.d0325;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateTimeFormatterTest {
    public static void main(String[] args) {
        DateTimeFormatter dtf1=DateTimeFormatter.ofPattern("yyyy/MM/dd");
        DateTimeFormatter dtf2=DateTimeFormatter.ofPattern("HH时mm分ss秒");
        DateTimeFormatter dtf3=DateTimeFormatter.ofPattern("yyyy/MM/dd HH时mm分ss秒");
        LocalDate date=LocalDate.now();
        LocalTime time=LocalTime.now();
        LocalDateTime datetime=LocalDateTime.now();
        Date date1=new Date();
        System.out.println(date1.getTime());//现在的毫秒数

        System.out.println(date.format(dtf1));
        System.out.println(time.format(dtf2));
        System.out.println(datetime.format(dtf3));

        String str1="2001/12/03";
        String str2="13时25分44秒";
        String str3="2023/06/14 07时08分20秒";
        LocalDate date2=LocalDate.parse(str1,dtf1);
        LocalTime time2=LocalTime.parse(str2,dtf2);
        LocalDateTime datetime2=LocalDateTime.parse(str3,dtf3);
        System.out.println(date2);
        System.out.println(time2);
        System.out.println(datetime2);
    }
}
